<html>
<head><meta charset="utf-8"><title>Unexpected error on trait where bounds · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html">Unexpected error on trait where bounds</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="243950912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243950912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243950912">(Jun 25 2021 at 18:09)</a>:</h4>
<p>I have a question about trait bound resolution, and wasn't able to find an issue on github related to it (I suspect there is one, but I'm not sure what to search for):</p>
<p>This playground fails to compile, despite the bounds looking like they should ensure that the error situation should never happen<br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=bad85946a6fbab31976393d7a7419316">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=bad85946a6fbab31976393d7a7419316</a><br>
Is there a reason for this? Would not rejecting it allow unsoundness, or is this a hole in resolution, or something else?</p>



<a name="243955105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243955105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243955105">(Jun 25 2021 at 18:47)</a>:</h4>
<p>What would you expect here?</p>



<a name="243955124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243955124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243955124">(Jun 25 2021 at 18:47)</a>:</h4>
<p>The bounds must apply for an impl to be allowed</p>



<a name="243955266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243955266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243955266">(Jun 25 2021 at 18:48)</a>:</h4>
<p>There is no <code>impl&lt;'a&gt; Add&lt;Bar&gt; for &amp;'a Bar { type Output = Bar; }</code></p>



<a name="243959669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243959669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243959669">(Jun 25 2021 at 19:27)</a>:</h4>
<p>I'd expect the function to compile. I included Bar to show that the compiler erroring on <em>both</em> the Bar impl and the use in the function seems odd, as one of those errors implies the other shouldn't happen: The trait can't be implemented if the <code>where</code> doesn't hold, so why do I need to repeat it on the function?</p>



<a name="243959721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243959721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243959721">(Jun 25 2021 at 19:27)</a>:</h4>
<p>I add that impl for Bar, and it can now implement Foo, but the function still fails to compile</p>



<a name="243959904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243959904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243959904">(Jun 25 2021 at 19:29)</a>:</h4>
<p>Basically: If a trait has certain bounds, I would expect those bounds to be implicitly included on any generic bound on the trait</p>



<a name="243960284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243960284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243960284">(Jun 25 2021 at 19:32)</a>:</h4>
<p>Oh I see</p>



<a name="243960312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243960312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243960312">(Jun 25 2021 at 19:32)</a>:</h4>
<p>Well</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">do_thing</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">Foo</span><span class="o">&gt;</span><span class="p">(</span><span class="n">item</span>: <span class="nc">T</span><span class="p">)</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="n">T</span>: <span class="nc">for</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Add</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"></span>
</code></pre></div>
<p>that suggestion is definitely wrong anyways lol</p>



<a name="243960454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243960454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243960454">(Jun 25 2021 at 19:34)</a>:</h4>
<p>Definitely seems weird</p>



<a name="243960979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243960979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243960979">(Jun 25 2021 at 19:38)</a>:</h4>
<p>seems like the implied bounds when we WF check <code>T: Foo</code> is probably not correct</p>



<a name="243963238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243963238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243963238">(Jun 25 2021 at 19:58)</a>:</h4>
<p>Okay, makes sense. I'm not super familiar with how the compiler actually handles well-formedness predicates, I only touched them indirectly as part of playing with making rust-call a little more robust to incorrect usage a while ago. But I just was playing with something and ran into that, and was like 'Huh... I don't immediately see a reason that doesn't hold, but maybe there's a reason'</p>



<a name="243964362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unexpected%20error%20on%20trait%20where%20bounds/near/243964362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unexpected.20error.20on.20trait.20where.20bounds.html#243964362">(Jun 25 2021 at 20:06)</a>:</h4>
<p>Opened an issue: <a href="https://github.com/rust-lang/rust/issues/86635">https://github.com/rust-lang/rust/issues/86635</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>